﻿<!DOCTYPE HTML PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
<html>
<head lang="en">
    <title>称重</title>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0">
    <meta name="format-detection" content="telephone=no">
    <!-- Set render engine for 360 browser -->
    <meta name="renderer" content="webkit">
    <!-- No Baidu Siteapp-->
    <!--<meta http-equiv="Cache-Control" content="no-siteapp" />-->
    <META HTTP-EQUIV="pragma" CONTENT="no-cache">
    <META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">
    <META HTTP-EQUIV="expires" CONTENT="0">
    <link rel="alternate icon" type="image/png" href="favicon.png">
    <link rel="stylesheet" href="/scripts/amazeui/amazeui.min.css" />
    <link rel="stylesheet" href="../css/main.css" />
    <script src="/scripts/jquery-3.3.1.min.js"></script>
    <script src="/scripts/amazeui/amazeui.min.js"></script>

    <script src="/scripts/jquery.signalR-2.4.1.min.js"></script>
    <style>
        .list {
            width: 1000px !important;
        }

        .am-form {
            width: 100%;
            background: #fff;
        }

        .refresh-port {
            width: 80px !important;
            height: 30px !important;
        }
    </style>
    <script type="text/javascript">
        var wid;// 称重驱动id

        function loadDrivers(cb) {
            dds.iot.weight.getDrivers(function (data) {
                if (data) {
                    var options = [];
                    var keys = Object.keys(data)
                    for (var i = 0; i < keys.length; i++) {
                        options.push(`
<option value="${keys[i]}">${data[keys[i]]}</option>
`)
                    }
                    $('#drpWeightType').html(options.join(''));
                }
                cb()
            })

        }
        function loadPorts(cb) {
            dds.iot.weight.getPortNames(function (data) {
                if (data) {
                    var options = [];
                    for (var i = 0; i < data.length; i++) {
                        var index = data[i].replace("COM", "");
                        options.push(`
<option value="${index}">${data[i]}</option>
`)
                    }
                    $('#drpWeightPort').html(options.join(''));
                }
                if (cb)
                    cb()
            })
        }
        function start() {
            var $weight = $("#weight");
            var $drpWeightType = $('#drpWeightType');
            var $drpWeightPort = $('#drpWeightPort');
            var $txtWeightBaudRate = $('#txtWeightBaudRate');
            var type = $drpWeightType.val();
            var port = $drpWeightPort.val() || 1;
            var baudRate = $txtWeightBaudRate.val();
            console.log('type', type)
            // 调用电子秤
            dds.iot.weight.start({
                type: type,
                port: port,
                baudRate: baudRate,
                onUpdateWeight: function (data) {
                    $weight.html(data.weight);
                },
                complete: function (ar) {
                    if (!ar.Success) {
                        alert(ar.Message);
                    } else {
                        wid = ar.Data;
                    }
                }
            })
        }
        function closeWeight() {
            dds.iot.weight.close(wid)
        }
        // 窗口初始化事件（操作窗口大小、标题）
        $(document).bind('dds.window.init', function (e, win) {
            loadDrivers(function () {
            });
            loadPorts(function () {

            });
        })
    </script>

</head>

<body>
    <div class="fun_bd" style="padding-top:0px;">
        <div class="package-control">
            <div class="function">
                <div class="display">
                    <div style="color:#fff;display:none;">
                        <h3>今天统计</h3>
                        <span>
                            802.2
                            <span>kg</span>
                        </span>
                        <span>138/条</span>
                        <span>2871/元</span>
                    </div>
                    <div class="led">
                        <p id="weight">0.00</p>
                        <!--<span class="error hidden" id="saveError">error</span>-->
                    </div>
                    <div class="record" style="margin-top:0px;">
                        <ul id="showMsgUl">
                            <li id="Specifications">
                                <label>规格</label><input id="spectTextCurrent" type="text" readonly="" value="" />
                            </li>
                            <!--<li id="proweight">
                                <label>重量</label><input id="weight2Current" type="text" readonly="" value="" />
                            </li>-->
                            <li id="Hook_number">
                                <label>单价</label><input id="gghCurrent" type="text" readonly="" value="" />
                            </li>
                            <li id="IdentityCode">
                                <label>合计</label><input id="codeCurrent" type="text" readonly="" value="" />
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
            <div class="list" id="divSpecList">

                <form class="am-form">
                    <fieldset>
                        <div class="am-form-group">
                            <label for="doc-ipt-email-1" class="am-u-sm-4">电子秤型号</label>
                            <div class="am-u-sm-8">
                                <select id="drpWeightType">
                                </select>
                            </div>
                        </div>
                        <div class="am-form-group">
                            <label for="doc-ipt-email-1" class="am-u-sm-4">波特率</label>
                            <div class="am-u-sm-8">
                                <input id="txtWeightBaudRate" type="text" value="9600" />
                            </div>
                        </div>

                        <div class="am-form-group">
                            <label for="doc-ipt-email-1" class="am-u-sm-4">串口号</label>
                            <div class="am-u-sm-6">
                                <select id="drpWeightPort">
                                </select>
                            </div>
                            <label class="am-u-sm-2" style="padding-top: 5px;">
                                <a onclick="loadPorts()" class="refresh-port">刷新</a>
                            </label>
                        </div>
                        <div class="am-form-group">
                            <button onclick="start()" class="am-btn-primary" type="button">打开</button>
                            <button onclick="closeWeight()" class="am-btn-danger" type="button">关闭</button>
                        </div>

                    </fieldset>
                </form>
            </div>

        </div>
    </div>

</body>

</html>